<template>
    <el-dialog
        title="收货地址"
        :visible.sync="dialogFormVisible"
    >
        <el-form :model="form">
            <el-form-item label="标题" :label-width="formLabelWidth">
                <el-input v-model="form.title" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="内容" :label-width="formLabelWidth">
                <el-input v-model="form.content" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="作者" :label-width="formLabelWidth">
                <el-input v-model="form.author" autocomplete="off"></el-input>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible=false">取 消</el-button>
            <el-button type="primary" @click="Submit">确 定</el-button>
        </div>
    </el-dialog>
</template>

<script>
export default {
    watch: {
    },
    data() {
        return {
            form: {
                title: '',
                content: '',
                author: '',
            },
            formLabelWidth: '120px',
            dialogFormVisible:false,
        }
    },
    methods: {
        Submit() {
            if(this.form.id) {
                 this.$api.editList({
                     ...this.form,
                 }).then((res) => {
                    if (res.code === 1) {
                        this.form = {
                            title: '',
                            content: '',
                            author: '',
                        }
                        this.$emit('update');// 更新列表
                        this.dialogFormVisible = false;// 关闭弹框
                    }
                })
            } else {
                 this.$api.addList(this.form).then((res) => {
                    if (res.code === 1) {
                        this.form = {
                            title: '',
                            content: '',
                            author: '',
                        }
                        this.$emit('update')// 更新列表
                        this.dialogFormVisible = false; // 关闭弹框
                    }
                })
            }
           
        },
    },
}
</script>

<style>
</style>